home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9679 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  54 lines

  1. Path: lassen.cnw.com!matt!matt
  2. From: matt@matt.fidalgo.net (Matt Gischer)
  3. Newsgroups: comp.lang.c
  4. Subject: Paging program
  5. Date: Tue, 12 Mar 1996 08:02:17 GMT
  6. Organization: Uncle Fran's Musical Forest
  7. Message-ID: <Do5ABu.1v0@matt.fidalgo.net>
  8. NNTP-Posting-Host: fidnet-30.fidalgo.net
  9. X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
  10.  
  11. I'm trying to get this program here to work.  It's supposed to take a 
  12. file (from stdin or the command line) and pause every 24 lines.  
  13. (although i'd like some insight on how to find out how many rows the 
  14. users terminal has).  Anyway.. this thing prints out the last line of the 
  15. file however many lines it is short of a full page on the last page.  
  16. So.. i was wondering if anyone could help me with that. Thanks.
  17.  
  18. #include <stdio.h>
  19.  
  20. main(int argc, char *argv[])
  21. {
  22. FILE *in;
  23. char t[80],enter;
  24. int x=0,z=0,s=0,y=0;
  25. if((in=fopen(argv[1], "r"))==NULL) {
  26. in=stdin;
  27. }
  28. while(!feof(in)) {
  29. fgets(t, 79,in);
  30. x++;
  31. }
  32. x--;
  33. rewind(in);
  34. y=x/24;
  35. if((y*24)<x) {
  36. y++;
  37. }
  38. for(s=0;s<y;s++) {
  39.     for(z=0;z<24;z++) {
  40.         fgets(t,79,in);
  41.         if(t!=NULL) {
  42.             print(t);
  43.         }
  44.     }
  45.     if(x>=24) {
  46.     printf("Hit enter for more");
  47.     enter=getchar();
  48. }
  49. }
  50. fclose(in);
  51. return 0;
  52. }
  53.  
  54.